package com.ljx.date.date01;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;

/**
 * @author LJX
 * @Description: 用Period比较两个日期的距离，用Duration来比较两个时间的距离
 * @Date: 2022/11/7 15:17
 * @Version 1.0
 */
public class DateAndTimeComparator {
	public static void main(String[] args) {
		LocalDate localDate = LocalDate.of(2021, 1, 12);
		LocalDate localDate1 = LocalDate.now();
		// 比较两个日期的距离
		Period between = Period.between(localDate, localDate1);
		// 相差几年几月几天
		System.out.println(between.getYears());
		System.out.println(between.getMonths());
		System.out.println(between.getDays());


		LocalTime localTime1 = LocalTime.of(12, 12, 12);
		LocalTime now = LocalTime.now();
		Duration between1 = Duration.between(localTime1, now);
		// 相差几时几分几秒
		System.out.println(between1.toHours());
		System.out.println(between1.toMinutes());
		System.out.println(between1.toDays());
		System.out.println(between1.toMillis());
		System.out.println(between1.toNanos());


	}
}
